package com.pxmeta.user.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pxmeta.dynamic.entity.dto.ReportCircleDTO;
import com.pxmeta.dynamic.entity.dto.ReportPartyDTO;
import com.pxmeta.dynamic.entity.dto.ReportUserDTO;
import com.pxmeta.dynamic.service.IMailService;
import com.pxmeta.user.entity.UserReport;
import com.pxmeta.user.mapper.UserReportMapper;
import com.pxmeta.user.service.IUserReportService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wcl
 * @since 2022-07-13
 */
@Service
@RequiredArgsConstructor
public class UserReportServiceImpl extends ServiceImpl<UserReportMapper, UserReport> implements IUserReportService {

    private final IMailService mailService;

    @Override
    public void report(ReportUserDTO dto, Long userId) {
        UserReport userReport = new UserReport();
        userReport.setUserId(userId);
        userReport.setReportUserId(dto.getReportUserId());
        userReport.setReportChatGroupId(dto.getReportChatGroupId());
        List<String> imgList = dto.getImgList();
        if (CollectionUtil.isNotEmpty(imgList)){
            userReport.setImgUrls(StrUtil.join(",",imgList));
        }
        userReport.setType(dto.getType());
        userReport.setStatus(0);
        this.save(userReport);
        mailService.sendNoticeMessage(userId,1L,"亲爱的碰心友，已收到您的举报，官方会尽快核实，感谢您维护碰心的环境及美好的社区氛围~");
    }

    @Override
    public void report(ReportCircleDTO dto, Long userId) {
        UserReport userReport = new UserReport();
        userReport.setUserId(userId);
        userReport.setReportCircleId(dto.getReportCircleId());
        List<String> imgList = dto.getImgList();
        if (CollectionUtil.isNotEmpty(imgList)){
            userReport.setImgUrls(StrUtil.join(",",imgList));
        }
        userReport.setType(dto.getType());
        userReport.setStatus(0);
        this.save(userReport);
        mailService.sendNoticeMessage(userId,1L,"亲爱的碰心友，已收到您的举报，官方会尽快核实，感谢您维护碰心的环境及美好的社区氛围~");
    }

    @Override
    public void report(ReportPartyDTO dto, Long userId) {
        UserReport userReport = new UserReport();
        userReport.setUserId(userId);
        userReport.setReportCircleId(dto.getReportPartyId());
        List<String> imgList = dto.getImgList();
        if (CollectionUtil.isNotEmpty(imgList)){
            userReport.setImgUrls(StrUtil.join(",",imgList));
        }
        userReport.setType(dto.getType());
        userReport.setStatus(0);
        this.save(userReport);
        mailService.sendNoticeMessage(userId,1L,"亲爱的碰心友，已收到您的举报，官方会尽快核实，感谢您维护碰心的环境及美好的社区氛围~");
    }
}
